<template>
  <div class="order">
    <div @click="toAddressList" v-if="address.name" class="address">
      <div class="item">
        <div class="list">
          <div class="addresslist">
            <div>
              <span>{{address.name}}</span>
              <div v-if="address.is_default" class="moren">
                默认
              </div>
            </div>
            <div class="info">
              <p>{{address.mobile}}</p>
              <p>{{address.address+address.address_detail}}</p>
            </div>
            <div></div>
          </div>
        </div>
      </div>
    </div>
    <div @click="toAdd" v-else class="seladdress">
      请选择收货地址
    </div>
    <div class="orderbox">
      <div class="item">
        <div>商品合计</div>
        <div>￥{{allprice}}</div>
      </div>
      <div class="item">
        <div>运费</div>
        <div>免运费</div>
      </div>
      <div class="item">
        <div>优惠券</div>
        <div>暂无</div>
      </div>
    </div>
    <div class="cartlist">
      <div class="item" v-for="(item,index) in listData" :key="index">
        <div class="con">
          <div class="left">
            <div class="img">
              <img :src="item.list_pic_url" alt="">
            </div>
            <div class="info">
              <p>{{item.goods_name}}</p>
              <p>￥{{item.retail_price}}</p>
            </div>
          </div>
          <div class="right">
            <div class="num">
              x{{item.number}}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div>
        实付 : ￥{{allprice}}
      </div>
      <div @click="pay">
        支付
      </div>
    </div>
  </div>
</template>

<script>

  import {get, getStorageOpenid} from "../../utils";

  export default {
    data() {
      return {
        addressId: "",
        openId: "",
        allprice: "",
        listData: [],
        address: {}
      }
    },
    components: {},
    computed: {},
    created() {
    },
    mounted() {

    },
    methods: {

      async getDetail() {
        const data = await get("/order/detailAction", {
          openId: this.openId,
          addressId: this.addressId
        });
        console.log(data);
        if (data) {
          this.allprice = data.allPrise;
          this.listData = data.goodsList;
          // 先默认给一个演示收货地址
          // this.address = data.address;
          this.address = {
            name: 'PENG',
            mobile: '15088888888',
            address: '北京朝阳区奥运村街道',
            address_detail: '奥林匹克公园',
          };
        }
      },

      pay() {
        wx.showToast({
          title: "暂不支持该功能！",
          icon: 'none',
          duration: 2000
        });
        return;
        /**
         * 微信支付
         * https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter2_8_1.shtml
         */
        var payInfo = {};
        wx.requestPayment({
          timeStamp: payInfo.time_stamp,
          nonceStr: payInfo.nonce_str,
          package: payInfo.package,
          signType: payInfo.sign_type,
          paySign: payInfo.pay_sign,
          success: function (res) {
            console.log("pay success: " + res);
          },
          fail: function (res) {
            console.log("pay fail: " + res);
          },
          complete: function (res) {
            console.log("pay complete: " + res);
          }
        });
      },
      toAdd() {
        // 新增收货地址
      },
      toAddressList() {
        // 选择收货地址
      },

    },
    onShow() {
      if (wx.getStorageSync("addressId")) {
        this.addressId = wx.getStorageSync("addressId");
      }
      this.openId = getStorageOpenid();
      this.getDetail();
    },

  }

</script>

<style lang='scss' scoped>
  @import "./style.scss";
</style>
